import pandas as pd
import jieba
from snownlp import SnowNLP
import pyecharts.options as opts
from pyecharts.charts import WordCloud

data = pd.read_excel(r'H:\anaconda\数据可视化及开发\数据可视化\数据\披荆斩棘的哥哥短评.xlsx')
data_name = pd.read_excel(r'H:\anaconda\数据可视化及开发\数据可视化\数据\披荆斩棘的哥哥名字.xlsx')

data['分词'] = data['评论'].agg(lambda x: jieba.lcut(x))


# 哥哥热度统计函数
def heat_count(name, series):
    count = 0
    for i in series:
        for j in i:
            if j == name:
                count += 1
    return count


data_name['热度'] = data_name['名字'].agg(heat_count, series=data['分词'])

data_wordcloud_name = [(i,str(j)) for i,j in zip(data_name['名字'],data_name['热度'])]

c = (
    WordCloud()
    .add(series_name="",
         data_pair=data_wordcloud_name,
         word_size_range=[20, 80]
        )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="哥哥的热度", title_textstyle_opts=opts.TextStyleOpts(font_size=23)
        ),
        tooltip_opts=opts.TooltipOpts(is_show=True),
    )
)

c.render(r"../TestHTML/ciyun.html")
